#!/bin/bash
CWD=$(cd `dirname $0`;pwd)
cd "${CWD}"
source _env

cd /usr/sysbench/share/sysbench
export LD_LIBRARY_PATH=/u01/mysql/lib/
SYSBENCH=/usr/sysbench/bin/sysbench
SYSBENCH_SCRIPT=${SYSBENCH_SCRIPT:-"/usr/sysbench/share/sysbench/oltp_point_select.lua"}
SYSBENCH_TABLE_SIZE=${SYSBENCH_TABLE_SIZE:-20000}
SYSBENCH_TABLE_NUM=${SYSBENCH_TABLE_NUM:-32}
SYSBENCH_THREADS=${SYSBENCH_THREADS:-32}
SYSBENCH_REPORT_INTERVAL=${SYSBENCH_REPORT_INTERVAL:-2}
SYSBENCH_TIME=${SYSBENCH_TIME:-120}

SYSBENCH_CMD="${SYSBENCH} ${SYSBENCH_SCRIPT} --mysql-host=127.0.0.1 --mysql-port=${OB_MYSQL_PORT} --mysql-db=test --mysql-user=test@${OB_TENANT_NAME} --table_size=${SYSBENCH_TABLE_SIZE} --tables=${SYSBENCH_TABLE_NUM} --threads=${SYSBENCH_THREADS} --report-interval=${SYSBENCH_REPORT_INTERVAL} --time=${SYSBENCH_TIME}"


case "$1" in
    cleanup)
        set -x
        ${SYSBENCH_CMD} cleanup
        ;;
    prepare)
        set -x
        ${SYSBENCH_CMD} prepare
        ;;
    run)
        set -x
        ${SYSBENCH_CMD} --db-ps-mode=disable run
        ;;
    *)
        set -x
        ${SYSBENCH_CMD} cleanup
        ${SYSBENCH_CMD} prepare
        ${SYSBENCH_CMD} --db-ps-mode=disable run
        ;;
esac
